package top.wenzz.manage.system.manage.service;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.wenzz.commons.service.BasicService;
import top.wenzz.commons.utils.SpringSecurityUtils;
import top.wenzz.commons.vo.PageRequest;
import top.wenzz.manage.system.manage.dao.OvertimeRecordDao;
import top.wenzz.manage.system.manage.entity.OvertimeRecord;
import top.wenzz.manage.system.manage.entity.SysUser;

import java.util.List;
import java.util.Map;

/**
 * 加班记录service
 * Created by 钟廷员 on 2017/8/8.
 */
@Service
public class OvertimeRecordService extends BasicService<OvertimeRecord, OvertimeRecordDao> {
    @Override
    public Map<String, Object> find(OvertimeRecord entity, PageRequest pageRequest) {
        pageRequest.setSort(new Sort(Sort.Direction.DESC, "date"));
        return super.find(entity, pageRequest);
    }

    @Transactional
    public String batchSave(List<OvertimeRecord> entitys) throws Exception {
        SysUser user = SysUser.builder().id(SpringSecurityUtils.getUserByContext().getId()).build();
        entitys.forEach(e -> e.setUser(user));
        dao.save(entitys);
        return null;
    }
}
